<?php
/**
 * Created by PhpStorm.
 * User: PHP
 * Date: 2021/6/10
 * Time: 15:44
 */
namespace App\Http\Admin\Controllers\Config;
use App\Http\Controllers\Controller;
use Hlcreation\Basic\Helper;
use Illuminate\Http\Request;
use App\Requests\UploadRequest;

use App\Services\config\OrmServices;

class OrmController extends Controller
{

    public function __construct(OrmServices $services)
    {
        $this->services = $services;
    }


    //文件上传
    public function fileUpload(Request $request){

        $file=$request->file('file');

        if ($file->isValid()) {

            $data =  Helper::uploadImg($file);
            //dd($data);
            if($data){
                return Helper::toJson("上传图片成功", 200,$data);
            }else{
                return Helper::toJson("上传图片失败", 400);
            }
        }
        return  Helper::toJson('上传失败',400,[]);

    }



    //添加存储配置   1 是阿里云上传配置   2 是腾讯云上传配置  3是囚牛云上传配置  6是ORM
    public function orm_add(UploadRequest $request){

        $all = $request->all();
        if (empty($all['type'])){
            return Helper::toJson("ORM类型不能为空", 400);
        }
        $userInfo = Helper::getPost('userinfo');
        $all['creator_uid'] = $userInfo['user_info']['id'];  //创建者
        $all['created_at'] = date("Y-m-d H:i:s");

        $data = $this->services->OrmSave($all);
        if($data){
            return Helper::toJson("配置成功", 200);
        }else{
            return Helper::toJson("配置失败", 400);
        }
    }






    //查看阿里云信息   1 是阿里云上传配置   2 是腾讯云上传配置  3是囚牛云上传配置
    public function orm_info(Request $request){

        $userInfo = Helper::getPost('userinfo');

        $uid = $userInfo['user_info']['id'];  //创建者

        $type = $request->only('type');

        $data = $this->services->OrmInfo($uid,$type);


        return  Helper::toJson('orm配置详情 ',200,$data);

    }



    //配置列表
    public function configList(Request $request){
        $userInfo = Helper::getPost('userinfo');

        $uid = $userInfo['user_info']['id'];  //创建者

        $data = $this->services->configInfos($uid);

        return  Helper::toJson('orm配置详情 ',200,$data);


    }



    //开启关闭配置
    public function configOpen(Request $request){
        $userInfo = Helper::getPost('userinfo');

        $uid = $userInfo['user_info']['id'];  //创建者

        $type =  Helper::getPost('type');

        $status =  Helper::getPost('status');

        $data = $this->services->configOpen($uid,$type,$status);

        if ($data){
            return  Helper::toJson('操作成功 ',200);
        }else{
            return  Helper::toJson('操作失败 ',200);
        }


    }















}
